﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElCharro01.Models;

namespace ElCharro01.Controllers
{ 
    public class CartController : Controller
    {
        private Entities db = new Entities();

        //
        // GET: /Cart/

        public ViewResult Index()
        {
            return View(db.CartSet.ToList());
        }

        //
        // GET: /Cart/Details/5

        public ViewResult Details(int id)
        {
            Cart cart = db.CartSet.Single(c => c.Id == id);
            return View(cart);
        }

        //
        // POST: /Cart/Create

        [HttpPost]
        public ActionResult Create(Variant variant)
        {
         
            return null;
        }
        
        //
        // GET: /Cart/Edit/5
 
        public ActionResult Edit(int id)
        {
            Cart cart = db.CartSet.Single(c => c.Id == id);
            return View(cart);
        }

        //
        // POST: /Cart/Edit/5

        [HttpPost]
        public ActionResult Edit(Cart cart)
        {
            if (ModelState.IsValid)
            {
                db.CartSet.Attach(cart);
                db.ObjectStateManager.ChangeObjectState(cart, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(cart);
        }

        //
        // GET: /Cart/Delete/5
 
        public ActionResult Delete(int id)
        {
            Cart cart = db.CartSet.Single(c => c.Id == id);
            return View(cart);
        }

        //
        // POST: /Cart/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Cart cart = db.CartSet.Single(c => c.Id == id);
            db.CartSet.DeleteObject(cart);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}